#ifndef _timberyard_queue_h_
#define _timberyard_queue_h_

#include <queue>
#include <boost/thread/condition.hpp>
#include <boost/thread/mutex.hpp>
#include <timberyard/utils.h>

namespace Timberyard {

template <typename Contents>
class Queue : private Uncopyable, protected std::queue<Contents> {
	public:
		Queue() : std::queue<Contents>(),m_mutex(),m_cond() {}
		void Push(const Contents& c) {
			{ // lock
			boost::mutex::scoped_lock lock(m_mutex);
			this->push(c);
			}
			if (this->size()==1) m_cond.notify_all();
		};
		Contents Pop() {
			boost::mutex::scoped_lock lock(m_mutex);
			while (this->empty()) {
				m_cond.wait(lock);
			}
			Contents c=this->front();
			this->pop();
			return c;
		};
		unsigned int size () const {
			boost::mutex::scoped_lock lock(m_mutex); 
			return std::queue<Contents>::size();
		}
	protected:
		mutable boost::mutex m_mutex;
		boost::condition m_cond;
};

}

#endif // _timberyard_queue_h_
